#include "windows.h"

windows::windows() {
    ptrGrafics = NULL;

}

windows::~windows() {


}


winText windows::getTextByHandle(int pHandle) {
    //
}


winImage windows::getImageByHandle(int pHandle) {
    //
}


winEdit windows::getEditByHandle(int pHandle) {
    //
}


winButton windows::getButtonByHandle(int pHandle) {
    int i;
    winButton retVal;
    for(i=0;i<textCount;i++) {
        if(button[i].handle == pHandle) retVal = button[i];
    }
    return retVal;
}


bool windows::Render(void) {
    textprintf_ex(screen, font, 200, 10, makecol(255, 255, 255), -1, "Render: %i/%i",x, y);

    if(!sfWindowMap) textprintf_ex(screen, font, 200, 20, makecol(255, 255, 255), -1, "NULL %i/%i",x, y);
    else textprintf_ex(screen, font, 200, 30, makecol(255, 255, 255), -1, "NOT NULL %i/%i",x, y);

    textprintf_ex(screen, font, 40, 0, makecol(255, 255, 255), -1, "Bitmap size: (%dx%d)\n", sfWindowMap->w, sfWindowMap->h);


    //########################### Window ITSELF ###########################


    // Links Oben
    blit(sfWindowMap,
         ptrBuffer,
         posWindow[design][0].x,
         posWindow[design][0].y,
         0,
         0,
         posWindow[design][0].w,
         posWindow[design][0].h);

    // Links Unten
    blit(sfWindowMap,
         ptrBuffer,
         posWindow[design][6].x,
         posWindow[design][6].y,
         0,
         h-posWindow[design][6].h,
         posWindow[design][6].w,
         posWindow[design][6].h);


    // Rechts Unten
    if(resizable) blit(sfWindowMap,
                ptrBuffer,
                posWindow[design][10].x,
                posWindow[design][10].y,
                w-posWindow[design][10].w,
                h-posWindow[design][10].h,
                posWindow[design][10].w,
                posWindow[design][10].h);
    else blit(sfWindowMap,
              ptrBuffer,
              posWindow[design][8].x,
              posWindow[design][8].y,
              w-posWindow[design][8].w,
              h-posWindow[design][8].h,
              posWindow[design][8].w,
              posWindow[design][8].h);


    // Rechts Oben
    blit(sfWindowMap,
         ptrBuffer,
         posWindow[design][2].x,
         posWindow[design][2].y,
         w-posWindow[design][2].w,
         0,
         posWindow[design][2].w,
         posWindow[design][2].h);



    // Oben
    stretch_blit(sfWindowMap,
                 ptrBuffer,
                 posWindow[design][1].x,
                 posWindow[design][1].y,
                 posWindow[design][1].w,
                 posWindow[design][1].h,
                 posWindow[design][1].w,
                 0,
                 w-(posWindow[design][1].w*2),
                 posWindow[design][3].h   );


    // Links
    stretch_blit(sfWindowMap,
                 ptrBuffer,
                 posWindow[design][3].x,
                 posWindow[design][3].y,
                 posWindow[design][3].w,
                 posWindow[design][3].h,
                 0,
                 posWindow[design][3].h,
                 posWindow[design][1].w,
                 h-(posWindow[design][3].h*2));


    // Rechts
    stretch_blit(sfWindowMap,
                 ptrBuffer,
                 posWindow[design][5].x,
                 posWindow[design][5].y,
                 posWindow[design][5].w,
                 posWindow[design][5].h,
                 w-posWindow[design][5].w,
                 posWindow[design][5].h,
                 posWindow[design][5].w   ,
                 h-(posWindow[design][5].h*2));


    // Unten
    stretch_blit(sfWindowMap,
                 ptrBuffer,
                 posWindow[design][7].x,
                 posWindow[design][7].y,
                 posWindow[design][7].w,
                 posWindow[design][7].h,
                 posWindow[design][7].w,
                 h-posWindow[design][7].h,
                 w-(posWindow[design][7].w*2),
                 posWindow[design][7].h);


    // Inhalt
    stretch_blit(sfWindowMap,
                 ptrBuffer,
                 posWindow[design][4].x,
                 posWindow[design][4].y,
                 posWindow[design][4].w,
                 posWindow[design][4].h,
                 posWindow[design][4].w,
                 posWindow[design][4].h,
                 w-(posWindow[design][4].w*2),
                 h-(posWindow[design][4].h*2));


    // Menue
    if(menue) blit(sfWindowMap,
                ptrBuffer,
                posWindow[design][9].x,
                posWindow[design][9].y,
                w-posWindow[design][9].w,
                0,
                posWindow[design][9].w,
                posWindow[design][9].h);

    //########################### Content ITSELF ###########################

    //TODO LOOP FOR THE SUB OBJECTS LIKE BUTTON, ASO. RENDER IN OBJECTS ITSELF

}


bool windows::Draw(void) {
    blit(ptrBuffer, screen, 0, 0, x, y, w, h);
    textprintf_ex(screen, font, x+10, y+4, makecol(255, 255, 255), -1, "%s", title.c_str());
}
